<template>
    <view>
        <!-- parse <include src="../component/navigationBar.wxml"></include> -->
        <block>
            <view class="navigationBox" :style="'padding-top:' + nTop + 'px;height:' + nHeight + 'px;line-height:' + nHeight + 'px;--color:' + color + ';'">
                <view class="nBar" :style="'height:' + nHeight + 'px;top:' + nTop + 'px'">
                    <navigator class="ico" hoverClass="none" :openType="pages.length == 1 ? 'switchTab' : 'navigateBack'" :url="pages.length == 1 ? '/pages/index/index4' : ''">
                        {{ pages.length == 1 ? '' : '' }}
                    </navigator>
                    <view class="title">{{ nTitle }}</view>
                </view>
            </view>
        </block>
        <scroll-view
            @refresherrefresh="onPullDownRefresh"
            @scroll="binnd_scroll"
            @scrolltolower="onReachBottom"
            class="list"
            :enableBackToTop="true"
            :enableFlex="true"
            lowerThreshold="300"
            :refresherEnabled="true"
            :refresherTriggered="triggered"
            :scrollTop="scrolltopNum_index"
            :scrollWithAnimation="true"
            :scrollY="true"
            :style="'margin-top:' + nTH + 'px;height:-webkit-calc(100vh - ' + nTH + 'px);--color:' + color + ';--rgbcolor:' + rgbcolor + ';'"
        >
            <block v-if="LIST.length > 0" v-for="(dl, index) in LIST" :key="index">
                <view @tap="detailFn" class="dl" :data-id="item.id" :data-idx="index" :data-idx2="index2" v-for="(item, index2) in dl" :key="index2">
                    <view class="dt">
                        <view class="i ico k1"></view>
                        <text class="b" v-if="item.new == 1"></text>
                    </view>

                    <view class="dd">
                        <view class="h4">{{ item.title }}</view>
                    </view>

                    <view class="span">{{ item.addtime_str }}</view>
                </view>
            </block>
            <view class="nodata" v-if="party_nodata && LIST.length == 0">
                <image mode="aspectFit" src="/static/res/img/nodata.png"></image>
                暂无消息通知
            </view>
            <view class="loading" v-if="loading_flag">
                <image class="loading_ico" src="/static/res/img/loading_ico.svg" v-if="loading_ico_flag"></image>
                <text>{{ loading_str }}</text>
            </view>
            <view class="blank">　</view>
        </scroll-view>
        <view @tap="mask_closeFn" :class="'mask2 ' + mask_class" data-maskid="detail" v-if="detail">
            <view @tap.stop.prevent="emptyFn" class="div_box" style="--div_box_width: 600rpx; --div_box_height: 566rpx">
                <view @tap.stop.prevent="mask_closeFn" class="closebtm ico" data-maskid="detail"></view>
                <view class="h1">消息通知</view>
                <view class="C S15">
                    <view style="margin-bottom: 20rpx; border-bottom: #f5f5f5 1px solid; padding-bottom: 20rpx; color: #999">{{ detail_addtime }}</view>
                    <view style="text-align: left">{{ detail_content }}</view>
                </view>
            </view>
        </view>
        <!-- parse <include src="TG_btm_nav.wxml"></include> -->
        <block>
            <view
                class="btm_nav"
                :style="'--color:' + color + ';--rgbcolor:' + rgbcolor + ';--btmnavbg_color:' + btmnavbg_color + ';--btmnavbg_rgbcolor:' + btmnavbg_rgbcolor + ';'"
            >
                <view class="shadow"></view>
                <view class="navabox">
                    <navigator :class="'a ' + (btm_nav == 'index' ? ' ed' : '')" hoverClass="none" openType="redirect" :url="'index?tguid=' + tguid + '&admid=' + admid">
                        <view class="i">
                            <view class="image ico"></view>
                        </view>
                        <view class="font">首页</view>
                    </navigator>
                    <navigator :class="'a ' + (btm_nav == 'help' ? ' ed' : '')" hoverClass="none" openType="redirect" :url="'help?tguid=' + tguid + '&admid=' + admid">
                        <view class="i">
                            <view class="image ico"></view>
                        </view>
                        <view class="font">帮助</view>
                    </navigator>
                    <navigator :class="'a ' + (btm_nav == 'msg' ? ' ed' : '')" hoverClass="none" openType="redirect" :url="'msg?tguid=' + tguid + '&admid=' + admid">
                        <view class="i">
                            <view class="image ico"></view>
                            <text class="span" v-if="btm_nav_msg_num > 0">{{ btm_nav_msg_num }}</text>
                        </view>
                        <view class="font">通知</view>
                    </navigator>
                    <navigator :class="'a ' + (btm_nav == 'my' ? ' ed' : '')" hoverClass="none" openType="redirect" :url="'my?tguid=' + tguid + '&admid=' + admid">
                        <view class="i">
                            <view class="image ico"></view>
                        </view>
                        <view class="font">我的</view>
                    </navigator>
                </view>
            </view>
            <view @tap="backtopFn" class="backtop fadeInUp" data-id="index" :style="'color:' + color" v-if="backtop_flag">
                <text class="ico icon-backtop"></text>
                顶部
            </view>
        </block>
        <view @tap="backtopFn" class="backtop fadeInUp" data-id="index" :style="'color:' + color" v-if="backtop_flag">
            <text class="ico icon-backtop"></text>
            顶部
        </view>
    </view>
</template>
<script module="WXS" lang="wxs" src="@/res/www.a9a.cn.wxs"></script>
<script>
var t;
var a = require('../../@babel/runtime/helpers/defineProperty');
var i = require('../../res/www.a9a.cn.js');
var app = getApp();
var n = 2;
var s = true;
export default {
    data() {
        return {
            nTitle: '消息通知',
            btm_nav: 'msg',
            btmnavbg_color: '#B8BCCC',
            btmnavbg_rgbcolor: i.c16_rgb('#B8BCCC'),
            triggered: true,
            loading_flag: false,
            loading_ico_flag: false,
            loading_str: '玩命加载中',
            color: '',
            rgbcolor: '',
            tguid: '',
            admid: '',
            LIST: [],
            party_nodata: false,
            t: 0,
            btm_nav_msg_num: '',
            SHARE: '',
            MB: '',
            mask_class: '',
            backtop_flag: false,
            nTop: '',
            nHeight: '',
            pages: [],
            scrolltopNum_index: 0,
            nTH: '',
            dl: [],
            detail: '',
            detail_addtime: '',
            detail_content: ''
        };
    },
    onLoad: function (t) {
        var that = this;
        var n = 0;
        var s = 0;
        uni.setNavigationBarTitle({
            title: that.nTitle
        });
        app.globalData.get_config('_ZEAI').then(function (t) {
            that.setData({
                color: app.globalData._ZEAI.color,
                rgbcolor: i.c16_rgb(app.globalData._ZEAI.color)
            });
        });
        app.globalData.get_navigationBarTopHeight(that);
        if (i.ifint(t.tguid) || i.ifint(t.admid)) {
            n = i.ifint(t.tguid) ? t.tguid : 0;
            s = i.ifint(t.admid) ? t.admid : 0;
        }
        that.setData({
            tguid: n,
            admid: s
        });
        this.init();
    },
    onPullDownRefresh: function () {
        var that = this;
        uni.vibrateShort({
            type: 'heavy'
        });
        setTimeout(function () {
            that.setData({
                triggered: false,
                loading_flag: false,
                loading_str: '拼命加载中',
                LIST: [],
                party_nodata: false,
                t: 0
            });
            that.setloading('end', '拼命加载中');
            n = 2;
            that.init();
        }, 500);
    },
    onReachBottom: function () {
        var i = this.LIST;
        var that = this;
        if (s) {
            s = false;
            that.setloading('start', '拼命加载中');
            var o = {
                submitok: 'MSG',
                p: n,
                openid: t.openid,
                t: that.t
            };
            app.globalData.ajax({
                url: 'tg.php',
                data: o,
                success: function (t) {
                    if (1 == t.flag) {
                        var e = i.length;
                        if (t.LIST.length < 1) {
                            that.setloading('end', '已全部加载完毕');
                            return void (s = false);
                        }
                        that.setData(a({}, 'LIST[' + e + ']', t.LIST));
                        n += 1;
                        s = true;
                    } else {
                        uni.showToast({
                            title: t.msg,
                            icon: 'none',
                            mask: true
                        });
                    }
                    that.setloading('end', '上拉加载更多');
                }
            });
        }
    },
    onShareAppMessage: function (t) {
        return {
            imageUrl: this.SHARE.imgurl,
            title: this.SHARE.title,
            path: '/hnPages/tg/msg'
        };
    },
    onShareTimeline: function () {
        return {
            imageUrl: this.SHARE.imgurl,
            title: this.SHARE.title,
            query: '',
            path: '/hnPages/tg/msg'
        };
    },
    methods: {
        init: function () {
            var that = this;
            uni.showLoading({
                title: '玩命加载中...',
                mask: true
            });
            s = false;
            t = uni.getStorageSync('COOK_U');
            app.globalData.ajax({
                url: 'tg.php',
                data: {
                    submitok: 'MSG',
                    openid: t.openid,
                    tguid: that.tguid,
                    admid: that.admid
                },
                success: function (t) {
                    switch (t.flag) {
                        case '1':
                        case 1:
                            var e;
                            if (0 == t.LIST.length) {
                                that.setData({
                                    btm_nav_msg_num: t.btm_nav_msg_num,
                                    LIST: [],
                                    party_nodata: true,
                                    nTitle: t.nTitle,
                                    SHARE: t.SHARE,
                                    MB: t.MB
                                });
                            } else {
                                that.setData({
                                    btm_nav_msg_num: t.btm_nav_msg_num,
                                    'LIST[0]': t.LIST,
                                    nTitle: t.nTitle,
                                    SHARE: t.SHARE,
                                    MB: t.MB
                                });
                            }
                            break;
                        case 'flag0':
                        case 'flag_1':
                        case 'flag2':
                            uni.reLaunch({
                                url: 'reg?t=' + t.flag
                            });
                            break;
                        default:
                            t.this = that;
                            t.url = 'no';
                            i.sorry(t);
                    }
                    s = true;
                    uni.hideLoading();
                }
            });
        },

        detailFn: function (n) {
            var that = this;
            i.empty(that.MB) || app.globalData.openSetting(that.MB);
            var d = n.currentTarget.dataset.id;
            var o = n.currentTarget.dataset.idx;
            var r = n.currentTarget.dataset.idx2;
            t = uni.getStorageSync('COOK_U');
            1 == that.LIST[o][r].new
                ? app.globalData.ajax({
                      url: 'tg.php',
                      data: {
                          submitok: 'MSG_detail',
                          id: d,
                          openid: t.openid
                      },
                      success: function (t) {
                          if (1 == t.flag) {
                              var i;
                              var e = parseInt(that.btm_nav_msg_num);
                              if (1 == that.LIST[o][r].new && --e < 0) {
                                  e = 0;
                              }
                              that.setData(
                                  ((i = {
                                      detail: true,
                                      mask_class: 'alpha0_100',
                                      detail_addtime: that.LIST[o][r].addtime,
                                      detail_content: that.LIST[o][r].content
                                  }),
                                  a(i, 'LIST[' + o + '][' + r + '].new', 0),
                                  a(i, 'btm_nav_msg_num', e),
                                  i)
                              );
                          } else {
                              uni.showToast({
                                  title: t.msg,
                                  icon: 'none',
                                  mask: true
                              });
                          }
                      }
                  })
                : that.setData(
                      a(
                          {
                              detail: true,
                              mask_class: 'alpha0_100',
                              detail_addtime: that.LIST[o][r].addtime,
                              detail_content: that.LIST[o][r].content
                          },
                          'LIST[' + o + '][' + r + '].new',
                          0
                      )
                  );
        },

        mask_closeFn: function (t) {
            var that = this;
            var e = t.currentTarget.dataset.maskid;
            this.setData({
                mask_class: 'alpha100_0'
            });
            setTimeout(function () {
                that.setData(a({}, e, false));
            }, 500);
        },

        tFn: function (t) {
            var a = t.currentTarget.dataset.t;
            this.setData({
                triggered: false,
                loading_flag: false,
                loading_str: '拼命加载中',
                LIST: [],
                party_nodata: false,
                t: a
            });
            this.init();
        },

        nodatabackFn: function () {
            this.setData({
                triggered: false,
                loading_flag: false,
                loading_str: '拼命加载中',
                LIST: [],
                party_nodata: false,
                t: 0
            });
            this.init();
        },

        setloading: function (t, a) {
            'start' == t
                ? this.setData({
                      loading_flag: true,
                      loading_ico_flag: true,
                      loading_str: a
                  })
                : this.setData({
                      loading_flag: false,
                      loading_ico_flag: false,
                      loading_str: a
                  });
        },

        binnd_scroll: function (t) {
            t.detail.scrollTop > 100
                ? this.setData({
                      backtop_flag: true
                  })
                : this.setData({
                      backtop_flag: false
                  });
        },

        backtopFn: function (t) {
            var i = 'scrolltopNum_' + t.currentTarget.dataset.id;
            this.setData(a({}, i, 0));
        },

        onPullDownRefresh() {
            console.log('占位：函数 onPullDownRefresh 未声明');
        },

        onReachBottom() {
            console.log('占位：函数 onReachBottom 未声明');
        },

        emptyFn() {
            console.log('占位：函数 emptyFn 未声明');
        }
    }
};
</script>
<style>
@import 'msg.css';
</style>
